//
//  LocationViewController.m
//  TravelEveryDay
//
//  Created by 路洪宇 on 15/10/16.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "LocationViewController.h"
#import "Play_LocationTableViewCell.h"
#import "BaseHeader.h"
@interface LocationViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation LocationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = TITLECOLOR;
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"play-close.png"] forState:UIControlStateNormal];
    backButton.frame = CGRectMake(SCREEN_WIDTH/2-12.5, SCREEN_HEIGHT-80*HEIGHT, 25, 25);
    [backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    
    _play_LocationArray = @[@"巴黎",@"北京",@"东京",@"上海",@"深圳",@"武汉",@"香港",@"悉尼"];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-100, 40, 200, 30)];
    [titleLabel setText:@"选择城市"];
    [titleLabel setFont:[UIFont systemFontOfSize:18.]];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:titleLabel];
    
    [self setUpTableView];
    [self setUpHeaderView];
}
-(void)setUpHeaderView
{
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150)];
    [backgroundView setBackgroundColor:TITLECOLOR];
    
    UILabel *hotLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20*HEIGHT, 100, 30)];
    [hotLabel setText:@"热门城市"];
    [hotLabel setTextColor:[UIColor whiteColor]];
    [hotLabel setTextAlignment:NSTextAlignmentLeft];
    [hotLabel setFont:[UIFont systemFontOfSize:15.]];
    hotLabel.alpha = 0.7;
    [backgroundView addSubview:hotLabel];
    
    _play_LocationTableView.tableHeaderView = backgroundView;
    
    UIButton *beiJinButton = [UIButton buttonWithType:UIButtonTypeCustom];
    beiJinButton.frame = CGRectMake(10, (hotLabel.frame.size.height + hotLabel.frame.origin.y+5)*HEIGHT, 80, 35);
    [beiJinButton setTitle:@"北京" forState:UIControlStateNormal];
    beiJinButton.titleLabel.font = [UIFont systemFontOfSize:15.];
    beiJinButton.layer.cornerRadius = 17;
    beiJinButton.layer.borderWidth = .5;
    beiJinButton.layer.masksToBounds = YES;
    beiJinButton.layer.borderColor = [[UIColor whiteColor]CGColor ];
    [beiJinButton addTarget:self action:@selector(beiJinClick) forControlEvents:UIControlEventTouchUpInside];
    [backgroundView addSubview:beiJinButton];
    
    UIButton *shangHaiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shangHaiButton.frame = CGRectMake(beiJinButton.frame.size.width+25, (hotLabel.frame.size.height + hotLabel.frame.origin.y+5)*HEIGHT, 80, 35);
    [shangHaiButton setTitle:@"上海" forState:UIControlStateNormal];
    shangHaiButton.titleLabel.font = [UIFont systemFontOfSize:15.];
    shangHaiButton.layer.cornerRadius = 17;
    shangHaiButton.layer.borderWidth = .5;
    shangHaiButton.layer.masksToBounds = YES;
    shangHaiButton.layer.borderColor = [[UIColor whiteColor]CGColor ];
    [shangHaiButton addTarget:self action:@selector(shangHaiClick) forControlEvents:UIControlEventTouchUpInside];

    [backgroundView addSubview:shangHaiButton];
    
    UILabel *allLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, shangHaiButton.frame.size.height+shangHaiButton.frame.origin.y+20, 100, 30)];
    [allLabel setText:@"全部城市"];
    [allLabel setTextColor:[UIColor whiteColor]];
    [allLabel setTextAlignment:NSTextAlignmentLeft];
    [allLabel setFont:[UIFont systemFontOfSize:15.]];
    allLabel.alpha = 0.7;
    [backgroundView addSubview:allLabel];
}

-(void)setUpTableView
{
    _play_LocationTableView  = [[UITableView alloc]initWithFrame:CGRectMake(0, 100*HEIGHT, SCREEN_WIDTH, 450*HEIGHT) style:UITableViewStylePlain];
    _play_LocationTableView.backgroundColor = TITLECOLOR;
    _play_LocationTableView.delegate = self;
    _play_LocationTableView.dataSource = self;
    [_play_LocationTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:_play_LocationTableView];
}

#pragma mark- TableView Delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _play_LocationArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60*HEIGHT;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"Play_LocationTableViewCell";
    Play_LocationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil)
    {
        cell = [[Play_LocationTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell.label setText:[self.play_LocationArray objectAtIndex:indexPath.row]];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate giveLocation:[self.play_LocationArray objectAtIndex:indexPath.row]];
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

-(void)beiJinClick
{
    [self.delegate giveLocation:@"北京"];
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

-(void)shangHaiClick
{
    [self.delegate giveLocation:@"上海"];
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}
-(void)backClick
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
